Suppression des *.pyc de subversion.
[minwii.git] / WiiMouse4IR coeff0.1.PIE
1 Wiimote1.led1 = true
2 Wiimote2.led1 = true
3 Wiimote2.led4 = true
4 Wiimote3.led2 = true
5 Wiimote4.led2 = true
6 Wiimote4.led4 = true
7 Wiimote5.led3 = true
8 Wiimote6.led3 = true
9 Wiimote6.led4 = true
10 //Mouse Control Script using IR
11 //by vkapadia with much assistance from inio
12 //vkapadia@vkapadia.com
13 //
14 //Calibration:
15 //To calibrate, run this program and put the Wiimote on a flat surface face-up.
16 //Then read the values in the debug line (next to the run button).
17 //Change these values until the debug line reads approx. all zeros.
18 var.xtrim1 = -1
19 var.ytrim1 = -25
20 var.ztrim1 = 2
21
22 var.xtrim2 = 3
23 var.ytrim2 = -30
24 var.ztrim2 = 2
25
26 var.xtrim3 = 2
27 var.ytrim3 = -27
28 var.ztrim3 = 2
29
30 var.xtrim4 = 2
31 var.ytrim4 = -30
32 var.ztrim4 = 2
33
34 var.coeff = 0.1
35
36 //
37 //Options:
38 var.deadzone = 5 //distance in pixels that you have to move the wiimote in
39 //order for it to register movement. Creates a "dead zone" around the pointer
40 //to make it easier to click. Higher = smoother but less accurate.
41 //fake cursor init
42
43 //cursor2.visible = true
44
45 //more options to be added later
46
47 //Controls:
48 //Point Wiimote = Move Mouse
49 //D-Pad = Arrow Keys
50 //B-Button = Left Click
51 //Home = Middle Click
52 //A-Button = Right Click
53 //Plus and Minus = Control Volume
54 //One = Unmapped
55 //Two = Unmapped
56 //
57 //If the pointer hits the edge of the screen, the Wiimote will rumble a bit.
58 //
59 //The LEDs attempt to emulate KITT's grill from Knight Rider
60
61 //WIIMOTE 1
62 //***Do not edit anything below this line unless you know what you are doing.***
63 var.accx1 = wiimote1.RawForceX + var.xtrim1
64 var.accy1 = wiimote1.RawForceY + var.ytrim1
65 var.accz1 = wiimote1.RawForceZ + var.ztrim1
66
67 if wiimote1.dot1vis and wiimote1.dot2vis then
68
69 if var.accy1 > -7 then
70 var.orientation1 = 0
71 elseif var.accy1 > -45 then
72 if var.accx1 < 0 then
73 var.orientation1 = 3
74 else
75 var.orientation1 = 1
76 endif
77 else
78 var.orientation1 = 2
79 endif
80
81 if var.leftpoint1 = 0 then
82 if var.orientation1 = 0 then
83 if wiimote1.dot1x < wiimote1.dot2x then
84 var.leftpoint1 = 1
85 else
86 var.leftpoint1 = 2
87 endif
88 endif
89 if var.orientation1 = 1 then
90 if wiimote1.dot1y > wiimote1.dot2y then
91 var.leftpoint1 = 1
92 else
93 var.leftpoint1 = 2
94 endif
95 endif
96 if var.orientation1 = 2 then
97 if wiimote1.dot1x > wiimote1.dot2x then
98 var.leftpoint1 = 1
99 else
100 var.leftpoint1 = 2
101 endif
102 endif
103 if var.orientation1 = 3 then
104 if wiimote1.dot1y < wiimote1.dot2y then
105 var.leftpoint1 = 1
106 else
107 var.leftpoint1 = 2
108 endif
109 endif
110 endif
111
112 if var.leftpoint1 = 1 then
113 var.fix1x1 = wiimote1.dot1x
114 var.fix1y1 = wiimote1.dot1y
115 var.fix2x1 = wiimote1.dot2x
116 var.fix2y1 = wiimote1.dot2y
117 else
118 var.fix1x1 = wiimote1.dot2x
119 var.fix1y1 = wiimote1.dot2y
120 var.fix2x1 = wiimote1.dot1x
121 var.fix2y1 = wiimote1.dot1y
122 endif
123
124 var.dx1 = var.fix2x1 - var.fix1x1
125 var.dy1 = var.fix2y1 - var.fix1y1
126 var.cx1 = (var.fix1x1+var.fix2x1)/1024.0 - 1
127 var.cy1 = (var.fix1y1+var.fix2y1)/1024.0 - .75
128
129 var.d1 = sqrt(var.dx1*var.dx1+var.dy1*var.dy1)
130
131 var.dx1 = var.dx1 / var.d1
132 var.dy1 = var.dy1 / var.d1
133
134 var.ox1 = -var.dy1*var.cy1-var.dx1*var.cx1;
135 var.oy1 = -var.dx1*var.cy1+var.dy1*var.cx1;
136
137 var.ax1 = (var.ox1 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2)
138 var.ay1 = (-var.oy1* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2)
139
140 var.dx1 = var.ax1 - cursor2.posx
141 var.dy1 = var.ay1 - cursor2.posy
142
143 var.d1 = sqrt((var.dx1*var.dx1)+(var.dy1*var.dy1))
144
145 var.a1 = 180 / (200 + var.d1 * var.d1 * var.d1 * .001)
146
147 if var.d1 <= var.deadzone then var.a1 = 1
148
149 //debug = var.d + " " + var.a
150
151 var.finalx1 = cursor2.posx * var.a1 + var.ax1 * (1 - var.a1)
152 var.finaly1 = cursor2.posy * var.a1 + var.ay1 * (1 - var.a1)
153
154
155 cursor2.posx = smooth(var.finalx1,3,5)
156 cursor2.posy = smooth(var.finaly1,3,5)
157
158 else
159
160 var.leftpoint1 = 0
161
162 endif
163
164 var.xpos1 = var.finalx1
165 var.ypos1 = var.finaly1
166 ppjoy1.analog0 = ensuremaprange(var.xpos1,0,screen.desktopwidth* var.coeff,-1,1)
167 ppjoy1.analog1 = ensuremaprange(var.ypos1,0,screen.desktopheight* var.coeff,-1,1)
168
169 if wiimote1.B or wiimote1.A or wiimote1.Up or wiimote1.down or wiimote1.Left or wiimote1.Right == true
170 ppjoy1.digital0 = true
171 else
172 ppjoy1.digital0 = false
173 endif
174
175 //WIIMOTE 2
176 //***Do not edit anything below this line unless you know what you are doing.***
177 var.accx2 = wiimote2.RawForceX + var.xtrim2
178 var.accy2 = wiimote2.RawForceY + var.ytrim2
179 var.accz2 = wiimote2.RawForceZ + var.ztrim2
180
181 if wiimote2.dot1vis and wiimote2.dot2vis then
182
183 if var.accy2 > -7 then
184 var.orientation2 = 0
185 elseif var.accy2 > -45 then
186 if var.accx2 < 0 then
187 var.orientation2 = 3
188 else
189 var.orientation2 = 1
190 endif
191 else
192 var.orientation2 = 2
193 endif
194
195 if var.leftpoint2 = 0 then
196 if var.orientation2 = 0 then
197 if wiimote2.dot1x < wiimote2.dot2x then
198 var.leftpoint2 = 1
199 else
200 var.leftpoint2 = 2
201 endif
202 endif
203 if var.orientation2 = 1 then
204 if wiimote2.dot1y > wiimote2.dot2y then
205 var.leftpoint2 = 1
206 else
207 var.leftpoint2 = 2
208 endif
209 endif
210 if var.orientation2 = 2 then
211 if wiimote2.dot1x > wiimote2.dot2x then
212 var.leftpoint2 = 1
213 else
214 var.leftpoint2 = 2
215 endif
216 endif
217 if var.orientation2 = 3 then
218 if wiimote2.dot1y < wiimote2.dot2y then
219 var.leftpoint2 = 1
220 else
221 var.leftpoint2 = 2
222 endif
223 endif
224 endif
225
226 if var.leftpoint2 = 1 then
227 var.fix1x2 = wiimote2.dot1x
228 var.fix1y2 = wiimote2.dot1y
229 var.fix2x2 = wiimote2.dot2x
230 var.fix2y2 = wiimote2.dot2y
231 else
232 var.fix1x2 = wiimote2.dot2x
233 var.fix1y2 = wiimote2.dot2y
234 var.fix2x2 = wiimote2.dot1x
235 var.fix2y2 = wiimote2.dot1y
236 endif
237
238 var.dx2 = var.fix2x2 - var.fix1x2
239 var.dy2 = var.fix2y2 - var.fix1y2
240 var.cx2 = (var.fix1x2+var.fix2x2)/1024.0 - 1
241 var.cy2 = (var.fix1y2+var.fix2y2)/1024.0 - .75
242
243 var.d2 = sqrt(var.dx2*var.dx2+var.dy2*var.dy2)
244
245 var.dx2 = var.dx2 / var.d2
246 var.dy2 = var.dy2 / var.d2
247
248 var.ox2 = -var.dy2*var.cy2-var.dx2*var.cx2;
249 var.oy2 = -var.dx2*var.cy2+var.dy2*var.cx2;
250
251 var.ax2 = (var.ox2 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2)
252 var.ay2 = (-var.oy2* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2)
253
254 var.dx2 = var.ax2 - cursor3.posx
255 var.dy2 = var.ay2 - cursor3.posy
256
257 var.d2 = sqrt((var.dx2*var.dx2)+(var.dy2*var.dy2))
258
259 var.a2 = 180 / (200 + var.d2 * var.d2 * var.d2 * .001)
260
261 if var.d2 <= var.deadzone then var.a2 = 1
262
263 //debug = var.d + " " + var.a
264
265 var.finalx2 = cursor3.posx * var.a2 + var.ax2 * (1 - var.a2)
266 var.finaly2 = cursor3.posy * var.a2 + var.ay2 * (1 - var.a2)
267
268
269 cursor3.posx = smooth(var.finalx2,3,5)
270 cursor3.posy = smooth(var.finaly2,3,5)
271
272 else
273
274 var.leftpoint2 = 0
275
276 endif
277
278 var.xpos2 = var.finalx2
279 var.ypos2 = var.finaly2
280 ppjoy2.analog0 = ensuremaprange(var.xpos2,0,screen.desktopwidth* var.coeff,-1,1)
281 ppjoy2.analog1 = ensuremaprange(var.ypos2,0,screen.desktopheight* var.coeff,-1,1)
282
283 if wiimote2.B or wiimote2.A or wiimote2.Up or wiimote2.down or wiimote2.Left or wiimote2.Right == true
284 ppjoy2.digital0 = true
285 else
286 ppjoy2.digital0 = false
287 endif
288
289 debug = var.accx2+ " " + var.accy2+ " " + var.accz2
290
291 //WIIMOTE 3
292 //***Do not edit anything below this line unless you know what you are doing.***
293 var.accx3 = wiimote3.RawForceX + var.xtrim3
294 var.accy3 = wiimote3.RawForceY + var.ytrim3
295 var.accz3 = wiimote3.RawForceZ + var.ztrim3
296
297 if wiimote3.dot1vis and wiimote3.dot2vis then
298
299 if var.accy3 > -7 then
300 var.orientation3 = 0
301 elseif var.accy3 > -45 then
302 if var.accx3 < 0 then
303 var.orientation3 = 3
304 else
305 var.orientation3 = 1
306 endif
307 else
308 var.orientation3 = 2
309 endif
310
311 if var.leftpoint3 = 0 then
312 if var.orientation3 = 0 then
313 if wiimote3.dot1x < wiimote3.dot2x then
314 var.leftpoint3 = 1
315 else
316 var.leftpoint3 = 2
317 endif
318 endif
319 if var.orientation3 = 1 then
320 if wiimote3.dot1y > wiimote3.dot2y then
321 var.leftpoint3 = 1
322 else
323 var.leftpoint3 = 2
324 endif
325 endif
326 if var.orientation3 = 2 then
327 if wiimote3.dot1x > wiimote3.dot2x then
328 var.leftpoint3 = 1
329 else
330 var.leftpoint3 = 2
331 endif
332 endif
333 if var.orientation3 = 3 then
334 if wiimote3.dot1y < wiimote3.dot2y then
335 var.leftpoint3 = 1
336 else
337 var.leftpoint3 = 2
338 endif
339 endif
340 endif
341
342 if var.leftpoint3 = 1 then
343 var.fix1x3 = wiimote3.dot1x
344 var.fix1y3 = wiimote3.dot1y
345 var.fix2x3 = wiimote3.dot2x
346 var.fix2y3 = wiimote3.dot2y
347 else
348 var.fix1x3 = wiimote3.dot2x
349 var.fix1y3 = wiimote3.dot2y
350 var.fix2x3 = wiimote3.dot1x
351 var.fix2y3 = wiimote3.dot1y
352 endif
353
354 var.dx3 = var.fix2x3 - var.fix1x3
355 var.dy3 = var.fix2y3 - var.fix1y3
356 var.cx3 = (var.fix1x3+var.fix2x3)/1024.0 - 1
357 var.cy3 = (var.fix1y3+var.fix2y3)/1024.0 - .75
358
359 var.d3 = sqrt(var.dx3*var.dx3+var.dy3*var.dy3)
360
361 var.dx3 = var.dx3 / var.d3
362 var.dy3 = var.dy3 / var.d3
363
364 var.ox3 = -var.dy3*var.cy3-var.dx3*var.cx3;
365 var.oy3 = -var.dx3*var.cy3+var.dy3*var.cx3;
366
367 var.ax3 = (var.ox3 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2)
368 var.ay3 = (-var.oy3* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2)
369
370 var.dx3 = var.ax3 - cursor4.posx
371 var.dy3 = var.ay3 - cursor4.posy
372
373 var.d3 = sqrt((var.dx3*var.dx3)+(var.dy3*var.dy3))
374
375 var.a3 = 180 / (200 + var.d3 * var.d3 * var.d3 * .001)
376
377 if var.d3 <= var.deadzone then var.a3 = 1
378
379 //debug = var.d + " " + var.a
380
381 var.finalx3 = cursor4.posx * var.a3 + var.ax3 * (1 - var.a3)
382 var.finaly3 = cursor4.posy * var.a3 + var.ay3 * (1 - var.a3)
383
384
385 cursor4.posx = smooth(var.finalx3,3,5)
386 cursor4.posy = smooth(var.finaly3,3,5)
387
388 else
389
390 var.leftpoint3 = 0
391
392 endif
393
394 var.xpos3 = var.finalx3
395 var.ypos3 = var.finaly3
396 ppjoy3.analog0 = ensuremaprange(var.xpos3,0,screen.desktopwidth* var.coeff,-1,1)
397 ppjoy3.analog1 = ensuremaprange(var.ypos3,0,screen.desktopheight* var.coeff,-1,1)
398
399 if wiimote3.B or wiimote3.A or wiimote3.Up or wiimote3.down or wiimote3.Left or wiimote3.Right == true
400 ppjoy3.digital0 = true
401 else
402 ppjoy3.digital0 = false
403 endif
404
405 debug = var.accx1+ " " + var.accy1+ " " + var.accz1
406
407 //WIIMOTE 3
408 //***Do not edit anything below this line unless you know what you are doing.***
409 var.accx4 = wiimote4.RawForceX + var.xtrim4
410 var.accy4 = wiimote4.RawForceY + var.ytrim4
411 var.accz4 = wiimote4.RawForceZ + var.ztrim4
412
413 if wiimote4.dot1vis and wiimote4.dot2vis then
414
415 if var.accy4 > -7 then
416 var.orientation4 = 0
417 elseif var.accy4 > -45 then
418 if var.accx4 < 0 then
419 var.orientation4 = 3
420 else
421 var.orientation4 = 1
422 endif
423 else
424 var.orientation4 = 2
425 endif
426
427 if var.leftpoint4 = 0 then
428 if var.orientation4 = 0 then
429 if wiimote4.dot1x < wiimote4.dot2x then
430 var.leftpoint4 = 1
431 else
432 var.leftpoint4 = 2
433 endif
434 endif
435 if var.orientation4 = 1 then
436 if wiimote4.dot1y > wiimote4.dot2y then
437 var.leftpoint4 = 1
438 else
439 var.leftpoint4 = 2
440 endif
441 endif
442 if var.orientation4 = 2 then
443 if wiimote4.dot1x > wiimote4.dot2x then
444 var.leftpoint4 = 1
445 else
446 var.leftpoint4 = 2
447 endif
448 endif
449 if var.orientation4 = 3 then
450 if wiimote4.dot1y < wiimote4.dot2y then
451 var.leftpoint4 = 1
452 else
453 var.leftpoint4 = 2
454 endif
455 endif
456 endif
457
458 if var.leftpoint4 = 1 then
459 var.fix1x4 = wiimote4.dot1x
460 var.fix1y4 = wiimote4.dot1y
461 var.fix2x4 = wiimote4.dot2x
462 var.fix2y4 = wiimote4.dot2y
463 else
464 var.fix1x4 = wiimote4.dot2x
465 var.fix1y4 = wiimote4.dot2y
466 var.fix2x4 = wiimote4.dot1x
467 var.fix2y4 = wiimote4.dot1y
468 endif
469
470 var.dx4 = var.fix2x4 - var.fix1x4
471 var.dy4 = var.fix2y4 - var.fix1y4
472 var.cx4 = (var.fix1x4+var.fix2x4)/1024.0 - 1
473 var.cy4 = (var.fix1y4+var.fix2y4)/1024.0 - .75
474
475 var.d4 = sqrt(var.dx4*var.dx4+var.dy4*var.dy4)
476
477 var.dx4 = var.dx4 / var.d4
478 var.dy4 = var.dy4 / var.d4
479
480 var.ox4 = -var.dy4*var.cy4-var.dx4*var.cx4;
481 var.oy4 = -var.dx4*var.cy4+var.dy4*var.cx4;
482
483 var.ax4 = (var.ox4 * var.coeff*screen.desktopwidth) + (screen.desktopwidth* var.coeff / 2)
484 var.ay4 = (-var.oy4* var.coeff * screen.desktopwidth) + (screen.desktopheight* var.coeff / 2)
485
486 var.dx4 = var.ax4 - cursor5.posx
487 var.dy4 = var.ay4 - cursor5.posy
488
489 var.d4 = sqrt((var.dx4*var.dx4)+(var.dy4*var.dy4))
490
491 var.a4 = 180 / (200 + var.d4 * var.d4 * var.d4 * .001)
492
493 if var.d4 <= var.deadzone then var.a4 = 1
494
495 //debug = var.d + " " + var.a
496
497 var.finalx4 = cursor5.posx * var.a4 + var.ax4 * (1 - var.a4)
498 var.finaly4 = cursor5.posy * var.a4 + var.ay4 * (1 - var.a4)
499
500
501 cursor5.posx = smooth(var.finalx4,3,5)
502 cursor5.posy = smooth(var.finaly4,3,5)
503
504 else
505
506 var.leftpoint4 = 0
507
508 endif
509
510 var.xpos4 = var.finalx4
511 var.ypos4 = var.finaly4
512 ppjoy4.analog0 = ensuremaprange(var.xpos4,0,screen.desktopwidth* var.coeff,-1,1)
513 ppjoy4.analog1 = ensuremaprange(var.ypos4,0,screen.desktopheight* var.coeff,-1,1)
514
515 if wiimote4.B or wiimote4.A or wiimote4.Up or wiimote4.down or wiimote4.Left or wiimote4.Right == true
516 ppjoy4.digital0 = true
517 else
518 ppjoy4.digital0 = false
519 endif
520